﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.CaseGrid = function (config) {

    Ext.apply(this, config);
    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/CaseService.aspx?Action=Search&CaseType=' + CaseType

        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Code', 'CaseType', 'ReportCaseTime', 'HappendArea', 'IsCallBack', 'Url']
        }),
        remoteStore: true
    });

    this.store = fileStore;
    var g = this.ParentG;
    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        noSort: true,
        defaultNum: 21
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();
    function renderLast(value, p, record) {
        if (value) {
            return String.format('<font color=black>{0}</font>', '是');
        }
        else {
            return String.format('<font color=red>{0}</font>', '否');
        }
    };

    function icon(value, p, record) {
        return String.format(
       "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript:onEdit({3},'{4}')\"><img src=\"Images/preview.png\" qtip=\"查看案件回访\"></a>",
                          value, record.data.Questioner, record.id, record.data.Id,g);
    }
    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    }, {
        header: '案件编号',
        dataIndex: 'Code',
        width: 200,
        sortable: true
    }, {
        header: '案件类型',
        dataIndex: 'CaseType',
        sortable: true
    }, {
        header: '报案时间',
        dataIndex: 'ReportCaseTime',
        sortable: true
    }, {
        header: '发案地点',
        dataIndex: 'HappendArea',
        width: 400,
        sortable: true
    }, {
        header: '是否回访',
        dataIndex: 'IsCallBack',
        renderer: renderLast,
        sortable: true
    }, {
        header: '',
        width: 100,
        dataIndex: 'Url',
        renderer: icon
    }]
    FantastPlatform.UI.CaseGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
}

Ext.extend(FantastPlatform.UI.CaseGrid, Ext.grid.GridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.CaseGrid.superclass.onRender.call(this, ct, position);
    },
    //刷新
    onUpdataCaseClick: function () {
        this.store.removeAll();
        this.store.proxy.conn = { method: 'post', url: this.url };
        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    }
});
    
